#include "Com_Delay.h"


void Com_Delayus(uint32_t us) {
    uint32_t i  =  us * (72 / 9);

    while (i--) {
        __NOP();
        __NOP();
    }
}
void Com_Delayms(uint32_t ms) {
    while (ms--) {
        Com_Delayus(1000); 
    }
}
void Com_Delays(uint32_t s) {
    while (s--) {
        Com_Delayms(1000);
    }
}
//实现UTC时间到北京时间的转换
void Com_UTCtime_to_Bj_Time(uint8_t *utc_time, uint8_t *bj_time) {
    struct tm tm_utc = {0};
    sscanf((char *)utc_time, "%d-%d-%d %d:%d:%d", &tm_utc.tm_year, &tm_utc.tm_mon, &tm_utc.tm_mday, &tm_utc.tm_hour, &tm_utc.tm_min, &tm_utc.tm_sec);
    tm_utc.tm_year -= 1900;
    tm_utc.tm_mon -= 1;

    time_t time_utc = mktime(&tm_utc);
    time_t time_bj = time_utc + 8 * 3600;
    struct tm *tm_bj = localtime(&time_bj);
    sprintf((char *)bj_time, "%04d-%02d-%02d %02d:%02d:%02d", tm_bj->tm_year + 1900, tm_bj->tm_mon + 1, tm_bj->tm_mday, tm_bj->tm_hour, tm_bj->tm_min, tm_bj->tm_sec);
}
